var CONTROLLER = 0;

var OP_UP = 0;
var OP_DOWN = 1;
var OP_LEFT = 2;
var OP_RIGHT = 3;

$(function () {
  var socket_url = "ws://" + window.location.hostname + ":8003";
  var socket = io(socket_url);

  socket.on("connect", function () {
    $("#status-show").css("background-color", "#a0d911");
  });

  socket.onclose = function () {
    $("#status-show").css("background-color", "#d4380d");
  };

  socket.onerror = function (event) {
    console.dir(event);
  };

  $("#up").click(function () {
    var data = {};
    data.sender = CONTROLLER;
    data.action = OP_UP;

    console.log(JSON.stringify(data));

    socket.send(JSON.stringify(data));
  });

  $("#down").click(function () {
    var data = {};
    data.sender = CONTROLLER;
    data.action = OP_DOWN;

    console.log(JSON.stringify(data));

    socket.send(JSON.stringify(data));
  });

  $("#left").click(function () {
    var data = {};
    data.sender = CONTROLLER;
    data.action = OP_LEFT;

    console.log(JSON.stringify(data));

    socket.send(JSON.stringify(data));
  });

  $("#right").click(function () {
    var data = {};
    data.sender = CONTROLLER;
    data.action = OP_RIGHT;

    console.log(JSON.stringify(data));

    socket.send(JSON.stringify(data));
  });
});
